#include "ZenFont.h"

CZenFont::CZenFont()
{
	m_pFont			= 0;
	m_FontColor		= D3DCOLOR_XRGB(255, 0, 0);
	m_bInitialized	= FALSE;
	m_Align			= DT_LEFT;
}

CZenFont::~CZenFont()
{
	if (m_pFont) 
	{
		m_pFont->Release();
	}
}

HRESULT	CZenFont::Inintialize(HFONT hFont, D3DCOLOR FontColor)
{
	HRESULT res;

	if (m_pFont) 
	{
		m_pFont->Release();
		m_pFont = 0;
	}

	res = D3DXCreateFont(zen.m_pDevice, hFont, &m_pFont);
	if (FAILED(res)) 
	{
		zen.SetError("Kan geen Font maken!");
		return E_FAIL;
	}
	
	m_FontColor		= FontColor;
	m_bInitialized	= TRUE;

	return S_OK;
}

HRESULT CZenFont::OutputText(char * pString, int x, int y)
{
	HRESULT res;

	if (!m_bInitialized)
		return E_FAIL;

	RECT FontRect = {x, y , 0 ,0};

	m_pFont->Begin();

	m_pFont->DrawText(pString, -1, &FontRect, DT_CALCRECT, 0);

	res = m_pFont->DrawText(pString, -1, &FontRect, m_Align, m_FontColor);

	m_pFont->End();

	return res;
}
